package devices

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"device_srv/deviceclient"

	"github.com/zeromicro/go-zero/core/logx"
)

// @Summary 设备信息修改
// @Description 拥有对应权限的用户可进行修改
// @Tags 修改
// @Accept json
// @Produce json
// @Param data body types.SendSmsReques true ""
// @Success 200 {object} types.Response
// @Failure 400 {string} types.Response
// @Failure 500 {string} types.Response
// @Router /devices/devicesUpdate [post]
type DevicesUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDevicesUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DevicesUpdateLogic {
	return &DevicesUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// DevicesUpdate 设备修改
func (l *DevicesUpdateLogic) DevicesUpdate(req *types.DevicesUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.DeviceRpc.DevicesUpdate(l.ctx, &deviceclient.DevicesUpdateRequest{
		Id:                req.Id,
		BrandId:           req.BrandId,
		DeviceName:        req.DeviceName,
		DeviceModel:       req.DeviceModel,
		DeviceDescription: req.DeviceDescription,
		PurchaseDate:      req.PurchaseDate,
		Status:            req.Status,
	})
	if err != nil {
		return respons.Error(400, "更新失败", err.Error()), err
	}
	return respons.Success(update), nil
}
